package com.lyh.system.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import com.lyh.common.enums.IncomeEnum;
import com.lyh.common.utils.DateUtils;
import com.lyh.system.domain.SysMemberUser;
import com.lyh.system.domain.vo.IncomeVo;
import com.lyh.system.service.ISysMemberUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lyh.system.mapper.IncomeMapper;
import com.lyh.system.domain.Income;
import com.lyh.system.service.IIncomeService;

/**
 * 收益Service业务层处理
 *
 * @author ruoyi
 * @date 2023-04-27
 */
@Service
public class IncomeServiceImpl implements IIncomeService {
    @Autowired
    private IncomeMapper incomeMapper;

    @Autowired
    private ISysMemberUserService memberUserService;

    /**
     * 查询收益
     *
     * @param id 收益主键
     * @return 收益
     */
    @Override
    public Income selectIncomeById(Long id) {
        return incomeMapper.selectIncomeById(id);
    }

    /**
     * 查询收益列表
     *
     * @param income 收益
     * @return 收益
     */
    @Override
    public List<Income> selectIncomeList(Income income) {
        return incomeMapper.selectIncomeList(income);
    }

    /**
     * 新增收益
     *
     * @param income 收益
     * @return 结果
     */
    @Override
    public int insertIncome(Income income) {
        income.setCreateTime(DateUtils.getNowDate());
        return incomeMapper.insertIncome(income);
    }

    /**
     * 修改收益
     *
     * @param income 收益
     * @return 结果
     */
    @Override
    public int updateIncome(Income income) {
        income.setUpdateTime(DateUtils.getNowDate());
        return incomeMapper.updateIncome(income);
    }

    /**
     * 批量删除收益
     *
     * @param ids 需要删除的收益主键
     * @return 结果
     */
    @Override
    public int deleteIncomeByIds(Long[] ids) {
        return incomeMapper.deleteIncomeByIds(ids);
    }

    /**
     * 删除收益信息
     *
     * @param id 收益主键
     * @return 结果
     */
    @Override
    public int deleteIncomeById(Long id) {
        return incomeMapper.deleteIncomeById(id);
    }

    @Override
    public IncomeVo selectAllList(Long id) {
        /*List<Income> incomes = selectIncomeListByMemberId(id);
        List<Income> dynamicList = new ArrayList<>();
        List<Income> staticList = new ArrayList<>();

        IncomeVo incomeVo = new IncomeVo();

        if (incomes != null && incomes.size() > 0) {
            BigDecimal dynamicAllIncome = new BigDecimal("0.0000");
            BigDecimal staticAllIncome = new BigDecimal("0.0000");
            for (Income income : incomes) {
                if (income.getIncomeNum() != null && IncomeEnum.DYNAMIC.name().equals(income.getType())) {
                    dynamicAllIncome = dynamicAllIncome.add(income.getIncomeNum());
                    dynamicList.add(income);
                }
                if (income.getIncomeNum() != null && IncomeEnum.STATIC.name().equals(income.getType())) {
                    staticAllIncome = staticAllIncome.add(income.getIncomeNum());
                    staticList.add(income);
                }
            }
            incomeVo.setDynamicAllIncome(dynamicAllIncome);
            incomeVo.setStaticAllIncome(staticAllIncome);
            incomeVo.setDynamicIncomeList(dynamicList);
            incomeVo.setStaticIncomeList(staticList);
            return incomeVo;
        }*/
        return null;
    }

    private List<Income> selectIncomeListByMemberId(Long id) {
        return incomeMapper.selectIncomeListByMemberId(id);
    }
}
